package org.lanqiao.api.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.dao.AdminDaoImpl;
import org.lanqiao.pojo.UserPOJO;
import org.lanqiao.service.AdminServiceImpl;

/**
 * 后台登录
 * Servlet implementation class AdminLoginServlet
 */
@WebServlet("/api/admin/AdminLoginServlet")
public class AdminLoginServlet extends HttpServlet {
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		/**
		 * 调用登录用户方法
		 */
		AdminDaoImpl abc=new AdminDaoImpl();
			UserPOJO user=new UserPOJO();
			JsonResult result=null;
			try {
				user=abc.loginUser(username, password);
				if(user!=null){
					result=new JsonResult("登录成功",Constants.STATUS_SUCCESS,user);
				}else {
					result=new JsonResult("登录错误",Constants.STATUS_UNFOUND);
				}
			} catch (Exception e) {
				result=new JsonResult("登录异常",Constants.STATUS_FAILURE);
			}
			JsonResultWriter.writer(response, result);;
	}

}
